<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>有奖答题平台</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <link rel="stylesheet" href="/mobile/css/bui.css" />
    <link rel="stylesheet" href="/lib/mobile/css/common.css?1111"/>
    <link rel="stylesheet" href="/lib/mobile/css/rank.css?000"/>
<style>
    .rank_rlist{width: 100%; margin: 0 auto; font-size: 0;}
    .rank_rlist5 li{width: 25%;}
</style>
</head>
<body>
    <ul class="rank_tabs">
        <li id="rank_person"><a href="javascript:void(0)">个人排行榜</a></li>
        <li class="on"  id="rank_company"><a href="javascript:void(0)">单位排行榜</a></li>
    </ul>
    <div class="rank_list">
        <dl>
            <dd class="on" id="monthon"><span><input type="text" id="month" style="width: 80px" readonly class="bui-input"></span><i></i></dd>
            <!--<dd id="yearon"><span><input type="text" id="year" style="width: 50px" readonly class="bui-input"></span><i></i></dd>-->
        </dl>
        <div class="rank_rlist rank_rlist5">
            <ol id="headColumn">
                <li style="width: 10%">序号</li>
                <li style="width: 50%">单位</li>
                <li style="width: 20%">平均积分</li>
                <li style="width: 20%">参与比例</li>
            </ol>
        </div>
    </div>
    <ul class="bottom_menu">
        <li  id="indexsy"><a href="javascript:void(0);">首页</a></li>
        <!--<li>|</li>-->
        <li  id="hdrule"><a href="javascript:void(0);">活动规则</a></li>
        <!--<li  id="point_rule"><a href="javascript:void(0);">积分规则</a></li>-->
        <!--<li>|</li>-->
        <!--<li id="prize_rule"><a href="javascript:void(0);">抽奖规则</a></li>-->
        <!--<li>|</li>-->
        <li id="center"><a href="javascript:void(0);">个人中心</a></li>
    </ul>
    <!--<div class="copyright">版权所有：天时集团能源有限公司</div>-->
    <!-- 依赖库 手机调试的js引用顺序如下 -->
    <script src="/lib/mobile/js/zepto.js"></script>
    <script src="/lib/mobile/js/plugins/fastclick.js"></script>
    <script src="/lib/mobile/js/bui.js"></script>
    <script src="/lib/mobile/js/common.js?11111    "></script>
    <script>
        bui.ready(function () {
            // 这里写业务及控件初始化
            var storage = bui.storage();
            dateSelect();
            root();
            changeDateStyle();
            bui.btn({id: ".bui-page", handle: ".bui-btn"}).load();
            myDeptPoint($("#month").val(),"month");
            var pageview = {};
            pageview.init = function () {
                // 验证码示例
                $("#indexsy").on("click", function (argument) {
                    bui.load({ url: BASE_URL+"mobile/index"});
                });
                $("#point_rule").on("click", function (argument) {
                    bui.load({ url: BASE_URL+"mobile/point_rule"});
                });
                $("#prize_rule").on("click", function (argument) {
                    bui.load({ url: BASE_URL+"mobile/prize_rule"});
                });
                $("#center").on("click", function (argument) {
                    bui.load({ url: BASE_URL+"mobile/center"});
                });
                var uid=storage.get("uid");
                //我的积分
                // getMyponit(uid[0]);
            }
            pageview.init();
        })
        function myDeptPoint(ny,flag) {
            //执行登录操作
            var loginAjax = bui.ajax({
                url: BASE_URL+"mobile/myDeptPoint",
                // 可选参数
                data: {
                    ny:ny,
                    flag:flag
                },
                method: "POST"
            });
            loginAjax.then(function(res) {
                if(res.code == 0){
                    var user = res.data;
                    var html='';
                    for(var i=0;i<user.length;i++){
                        var classname=''
                        if(i==0){
                            classname="<s class='first icon'></s>";
                        }else if(i==1){
                            classname="<s class='two icon'></s>";
                        }else if(i==2){
                            classname="<s class='three icon'></s>";
                        }else if(i>2){
                            classname="<s>lv."+(i+1)+"</s>";
                        }
                        var avgpoint = user[i].avgpoint;

                        if(!avgpoint){
                            avgpoint=0;
                        }
                        var dtrate = user[i].dtrate;
                        if(!dtrate){
                            dtrate=0;
                        }
                        html="<ul><li style=\"width: 10%\">"+classname+"</li>\n" +
                            "            <li style=\"width: 50%;text-align: left\">"+user[i].dept+"</li>\n" +
                            "            <li style=\"width: 20%\">"+avgpoint+"积分</li>\n" +
                            "            <li style=\"width: 20%\">"+dtrate+"%</li></ul>";
                        $("#headColumn").append(html);
                    }

                }else{
                    bui.alert(res.msg);
                }
            },function(res) {
                bui.alert("请求异常");
            })
        }
        function dateSelect() {
            var uiPickerdate = bui.pickerdate({
                handle: "#month",
                bindValue: true, // 1.5.3 新增, 修改的值会自动绑定到 handle, 不再需要自己去绑定
                // input 显示的日期格式
                formatValue: "yyyyMM",
                onChange: function(value) {
                },
                callback: function(e) {
                    $("#monthon").addClass("on");
                    myDeptPoint(this.value(),'month');
                },
                // 如果不需要按钮,设置为空
                // buttons: [{name:"取消"}]
            });
            uiPickerdate.cols({
                date: "none",
                hour: "none",
                minute: "none",
                second: "none"
            })
            var year = bui.pickerdate({
                handle: "#year",
                bindValue: true, // 1.5.3 新增, 修改的值会自动绑定到 handle, 不再需要自己去绑定
                // input 显示的日期格式
                formatValue: "yyyy",
                onChange: function(value) {
                },
                callback: function(e) {
                    $("#monthon").removeClass("on");
                    $("#yearon").addClass("on");
                    myDeptPoint('',this.value(),'year');
                },
                // 如果不需要按钮,设置为空
                // buttons: [{name:"取消"}]
            });
            year.cols({
                month: "none",
                date: "none",
                hour: "none",
                minute: "none",
                second: "none"
            })
        }
        function changeDateStyle() {
            $(".rank_list dd.on span").click(function () {
                $(this).removeClass('on');
            });
            $(".rank_list dd span").click(function () {
                $(this).addClass('on');
            });
        }
        function root() {
            $("#rank_person").on("click", function (argument) {
                $("#rank_person").addClass("on");
                $("#rank_company").removeClass("on");
                bui.load({ url: BASE_URL+"mobile/rank_person"});
            });
            $("#rank_company").on("click", function (argument) {
                $("#rank_company").addClass("on");
                $("#rank_person").removeClass("on");
                bui.load({ url: BASE_URL+"mobile/rank_company"});
            });
        }
    </script>
</body>
</html>
